package cn.wolfcode.car.service.impl;

import cn.wolfcode.car.domain.Permission;
import cn.wolfcode.car.mapper.PermissionMapper;
import cn.wolfcode.car.qo.PermissionQueryObject;
import cn.wolfcode.car.service.IPermissionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class PermissionServiceImpl implements IPermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public int delete(Long id) {
        return permissionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int save(Permission record) {
        return permissionMapper.insert(record);
    }

    @Override
    public Permission get(Long id) {
        return permissionMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Permission> list(PermissionQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Permission> list = permissionMapper.selectForQo(qo);
        return new PageInfo<>(list);
    }

    @Override
    public int update(Permission record) {
        return permissionMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Permission> listAll() {
        return permissionMapper.selectAll();
    }

    @Override
    public List<Permission> selectByRoleId(Long id) {
        return permissionMapper.selectByRoleId(id);
    }

    @Override
    public List<String> selectExpressionByEmployeeId(Long id) {

        return permissionMapper.selectExpressionByEmployeeId(id);
    }

    @Override
    public List<String> selectExpression() {
        return permissionMapper.selectExpression();

    }
}
